define(['dojo/_base/declare', 'geomap/plugins/layers/Echarts3Layer'], function (
    declare,
    Echarts3Layer
) {
    var EchartsLayer = declare([Echarts3Layer], {
        constructor: function (options) {
            this._map = options.map;
            if (!this._map) {
                return;
            }
            var echarts = options.echarts;
            var mouseEnabled = options.isNeedClick || options.mouseEnabled;
            var n = (this._echartsContainer = document.createElement('div'));

            (n.style.position = 'absolute'),
                (n.style.height = this._map.height + 'px'),
                (n.style.width = this._map.width + 'px'),
                (n.style.top = 0),
                (n.style.left = 0);

            if (this._map && this._map.__container) {
                var __container = this._map.__container;
                if (__container.childNodes && __container.childNodes.length > 0) {
                    var childNode = __container.childNodes[0];
                    if (mouseEnabled) {
                        childNode.appendChild(n);
                    } else {
                        childNode.insertBefore(n, childNode.getElementsByTagName('svg')[0]);
                    }
                }
            }
            this._init(this._map, echarts);
        },
        setData: function (mapView, layer) {
            var _this = this;
            _this._map = mapView.getMap();

            var o = layer.layer || {};
            var data = o.data;
            if (!data) {
                return;
            }
            data.geo = {
                map: '',
                roam: true,
            };

            var chartsContainer = _this.getEchartsContainer();

            var myCharts = _this.initECharts(chartsContainer);

            if (data.series && data.series.length > 0) {
                data.series.map(function (item) {
                    item.coordinateSystem = 'geo';
                });
            }
            _this.setOption(data);
            if (typeof o.callback == 'function') {
                o.callback(layer);
            }
        },
        removeLayer: function () {
            this._removeLayer();
        },
    });
    return EchartsLayer;
});
